﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MetMax.BusinessObject
{
    class RetentionAnalysis : Base
    {
        public RetentionAnalysis(
            Base bo
            , Fitting.Polynomial poly3fit_1stDimension
            , Fitting.Spline RelativeAlkanRetentionTime
            , Fitting.ObservationPointDictionary ri1system
            , Fitting.ObservationPointDictionary ri2system
            )
            : base(bo)
        {
            this.poly3fit_1stDimension = poly3fit_1stDimension;
            this.RelativeAlkanRetentionTime = RelativeAlkanRetentionTime;
            this.ri1system = ri1system;
            this.ri2system = ri2system;
        }

        public RetentionAnalysis(
            Base bo
            , string newMass
            , Fitting.Polynomial poly3fit_1stDimension
            , Fitting.Spline RelativeAlkanRetentionTime
            , Fitting.ObservationPointDictionary ri1system
            , Fitting.ObservationPointDictionary ri2system
            )
            : this(bo, poly3fit_1stDimension,RelativeAlkanRetentionTime,ri1system,ri2system)
        {
            mass = newMass;
        }

        #region Fittings
        public Fitting.Polynomial poly3fit_1stDimension { get; set; }
        public Fitting.Spline RelativeAlkanRetentionTime { get; set; }
        public Fitting.ObservationPointDictionary ri1system { get; set; }
        public Fitting.ObservationPointDictionary ri2system { get; set; }
        #endregion Fittings

        public float? ri1_by_poly3
        {
            get
            {
                if (!rt1.HasValue)
                {
                    return null;
                }
                return Convert.ToSingle(poly3fit_1stDimension.Interpolate(rt1.Value));
            }
        }

        public float? ri1_by_VanDenDool
        {
            get
            {
                if (!rt1.HasValue || ri1system.Count < 3)
                {
                    return null;
                }
                return Convert.ToSingle(Fitting.VanDenDool.ri(ri1system, rt1.Value));
            }
        }

        public float? ri1_by_Kovac
        {
            get
            {
                if (!rt1.HasValue || ri1system.Count < 3)
                {
                    return null;
                }
                return Convert.ToSingle(Fitting.Kovac.ri(ri1system, rt1.Value));
            }
        }

        public float? ri2_by_VanDenDool
        {
            get
            {
                if (!rt2.HasValue)
                {
                    return null;
                }
                return Convert.ToSingle(Fitting.VanDenDool.ri(ri2system, rt2wrapped.Value));
            }
        }

        public float? ReleativeAlkaneRetentionTime
        {
            get
            {
                if (!rt2.HasValue)
                {
                    return null;
                }
                return Convert.ToSingle(rt2wrapped.Value / RelativeAlkanRetentionTime.Interpolate(rt1.Value));
            }
        }

        public new object ValueNeeded()
        {
            switch (Properties.Settings.Default.myOptions.exportFact)
            {
                case DisplayProperties.firstDimensionVanDenDoolRi:
                    return ri1_by_VanDenDool;
                case DisplayProperties.firstDimensionKovacRi:
                    return ri1_by_Kovac;
                case DisplayProperties.secondDimensionVanDenDoolRi:
                    return ri2_by_VanDenDool;
                case DisplayProperties.secondDimensionReleativeAlkaneRt:
                    return ReleativeAlkaneRetentionTime;
                default:
                    return base.ValueNeeded();
            }
        }
    }
}
